package ua.com.globallogic.basecamp.krasnyanskiy.FileManager;

class SimpleCommand implements Command {
    private final String name;
    private final String arg;
    private final FileManager manager;

    SimpleCommand(String name, String arg, FileManager manager) {
        this.name = name;
        this.arg = arg;
        this.manager = manager;
    }

    @Override
    public void execute() throws ExitException {
        if (name.equals("cd")) {
            manager.changeDirectory(arg);
        } else if (name.equals("..")) {
            manager.setParentDirectory();
        } else if (name.equals("touch")) {
            manager.createFile(arg);
        } else if (name.equals("mkdir")) {
            manager.createDirectory(arg);
        } else if (name.equals("exit")) {
            throw new ExitException("Exit");
        } else if (name.equals("ls")) {
            if (arg == null) {
                manager.getDirectoryStructure();
            } else {
                manager.getDirectoryStructure(arg);
            }
        } else {
            System.out.println("Wrong command!");

        }
    }
}
